define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'calculation/salary/index' + location.search,
                    add_url: 'calculation/salary/add',
                    del_url: 'calculation/salary/del',
                    multi_url: 'calculation/salary/multi',
                    import_url: 'calculation/salary/import',
                    table: 'salary',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'start_time', title: __('Start_time'),datetimeFormat:'YYYY-MM-DD', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'),datetimeFormat:'YYYY-MM-DD', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'admin.nickname', title: __('Admin_id'), operate:false},
                        {field: 'create_time', title: __('Create_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'),searchList: {"0": '计算中', "1": '计算完成'},formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'),
                            buttons: [
                                {
                                    name: 'export',
                                    hidden:function(row){
                                        if(row.status == 0){
                                            return true; //或者return false
                                        }
                                    },
                                    text: '导出',
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary',
                                    url: 'calculation/salary/export',
                                    target: '_blank',
                                },
                                {
                                    name: 'preview',
                                    text: '查看工资数据',
                                    hidden:function(row){
                                        if(row.status == 0){
                                            return true; //或者return false
                                        }
                                    },
                                    icon: '',
                                    extend: 'data-area=\'["80%", "80%"]\'',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'my_salary/gongzi',
                                },
                            ],
                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
